package top.jacktgq.hsp.netty.tcp_selfprotocal;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @Author CandyWall
 * @Date 2020/11/13--17:54
 * @Description MessageProtocal编码器
 */
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocal> {
    @Override
    protected void encode(ChannelHandlerContext ctx, top.jacktgq.hsp.netty.tcp_selfprotocal.MessageProtocal msg, ByteBuf out) throws Exception {
        System.out.println("MyMessageEncoder的encode()方法被调用");
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
    }
}
